package com.topInterview;

public class leecode191 {
    public int getOne(int n) {
        int bit = 0;
        //最右测的1
        int rightOne = 0;
        while (n != 0) {
            //rightOne n& (~n+1)
            rightOne = n & (-n);
            //将最右测的1置为0
            n = n ^ rightOne;
            bit++;
        }
        return bit;
    }
}
